//
//  UILabel+DFSize.m
//  FrameWork
//
//  Created by 王*风 on ****/5/9.
//

#import "UILabel+DFSize.h"

@implementation UILabel (DFSize)

//获取宽度
+ (CGFloat)df_getTextWidthWithText:(NSString *)text height:(CGFloat)height font:(UIFont *)font
{
    CGSize newSize = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size;
    return newSize.width;
}

+ (CGFloat)df_getTextWidthWithText:(NSString *)text height:(CGFloat)height fontSize:(CGFloat)fontSize
{
    return [UILabel df_getTextWidthWithText:text height:height font:[UIFont systemFontOfSize:fontSize]];
}


//获取高度
+ (CGFloat)df_getTextHeightWithText:(NSString *)text width:(CGFloat)width font:(UIFont *)font
{
    CGSize newSize = [text boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size;
    return newSize.height;
}

+ (CGFloat)df_getTextHeightWithText:(NSString *)text width:(CGFloat)width fontSize:(CGFloat)fontSize
{
    return [UILabel df_getTextHeightWithText:text width:width font:[UIFont systemFontOfSize:fontSize]];
}

- (NSInteger)df_getlineCount:(CGSize)size fontSize:(CGFloat)fontSize
{
    CGRect rect = [self.text boundingRectWithSize:CGSizeMake(size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} context:nil];
    
    CGSize textSize = [self.text sizeWithAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:fontSize]}];
    
    return (NSUInteger)(rect.size.height / textSize.height);
}

@end
